﻿<?php
if(isset($_REQUEST['fuseaction_back'])) {
	$fuseaction_back=$_REQUEST['fuseaction_back'];
}else{
	$fuseaction_back = "";
}
if(isset($_REQUEST['hdn_worktype'])) {
	$v_worktype = $_REQUEST['hdn_worktype'];
}else{
	$v_worktype = "";
}
//Luu giu dieu kien loc
$v_page=1;
if(isset($_REQUEST['hdn_page'])){
	$v_page=intval($_REQUEST['hdn_page']);
}
$v_list_xml_tag = "";
if(isset($_REQUEST['hdn_list_xml_tag'])){
	$v_list_xml_tag = $_REQUEST['hdn_list_xml_tag'];
}
$v_list_xml_value = "";
if(isset($_REQUEST['hdn_list_xml_value'])){
	$v_list_xml_value = $_REQUEST['hdn_list_xml_value'];
}
$v_relate_record_code = "";
if(isset($_REQUEST['hdn_relate_record_code'])){
	$v_relate_record_code = _replace_bad_char($_REQUEST['hdn_relate_record_code']);
}
$v_staff_id = $_SESSION['staff_id'];
//var_dump($arr_single_record);
//Lay du lieu tu database
if ($v_record_id>0){
	$v_code_record = $arr_single_record['C_CODE'];
	$v_current_status = $arr_single_record['C_CURRENT_STATUS'];	
	$v_current_status_vunh = $arr_single_record['C_CURRENT_STATUS_VUNH'];
	$v_detail_status = $arr_single_record['C_DETAIL_STATUS'];
	$v_received_date = _yyyymmdd_to_ddmmyyyy($arr_single_record['C_RECEIVED_DATE']);
	$v_appointed_date = _yyyymmdd_to_ddmmyyyy($arr_single_record['C_APPOINTED_DATE']);
	$v_xml_str = $arr_single_record['C_RECEIVED_RECORD_XML_DATA'];
	$v_result_date = _yyyymmdd_to_ddmmyyyy($arr_single_record['C_RESULT_DATE']);
	$v_recordtype_filter = $arr_single_record['FK_RECORDTYPE'];
}else{
	if (_CONST_AUTOMATIC_RECORD_CODE_GENERATE){
		$v_code_record = onegate_generate_record_code($v_recordtype_filter);
	}else{
		$v_code_record = "";
	}
	$v_current_status = "";
	$v_current_status_vunh = "";
	$v_detail_status = "";
	$v_received_date = date("d/m/Y");
	$v_appointed_date = "";
	$v_recordtype_filter = "";
	$v_result_date = "";
	$v_xml_str = '<?xml version="1.0" encoding="UTF-8"?><root><data_list></data_list></root>';

}

//echo htmlspecialchars($v_xml_str);
$v_readonly = "";
if (_CONST_AUTOMATIC_RECORD_CODE_GENERATE){
	$v_readonly = "readonly";
}
//Duong dan den hop hien thi lich
$v_url_path_calendar = '"'.$_ISA_LIB_URL_PATH.'isa-calendar/"';
//So ngay xu ly doi voi moi loai ho so
$v_process_date = 0;
for ($i=0;$i < sizeof($_SESSION['recordtype']);$i++){
	if ($_SESSION['recordtype'][$i]['PK_RECORDTYPE']==$v_recordtype_filter){
		$v_process_date = $_SESSION['recordtype'][$i]['C_PROCESS_DATE'];
		break;
	}
}
$v_current_year = date("Y");
//echo htmlspecialchars($v_xml_str);
//cac file chua cau truc cua bang
$v_table_struct_xml_file = "../../xml/".$v_recordtype_filter."/cau_truc_bang_thong_tin_ve_ho_so_luu.xml";
$v_formfield_xml_file = "../../xml/".$v_recordtype_filter."/cac_dong_cua_thong_tin_ve_ho_so_luu.xml";
if (file_exists($v_table_struct_xml_file) && file_exists($v_table_struct_xml_file)){
	$v_table_struct_xml_string = _read_file($v_table_struct_xml_file);
	$v_formfield_xml_string = _read_file($v_formfield_xml_file);
}else{
	$v_table_struct_xml_file = "../../xml/other/cau_truc_bang_thong_tin_ve_ho_so_luu.xml";
	$v_formfield_xml_file = "../../xml/other/cac_dong_cua_thong_tin_ve_ho_so_luu.xml";
	$v_table_struct_xml_string = _read_file($v_table_struct_xml_file);
	$v_formfield_xml_string = _read_file($v_formfield_xml_file);
}
$v_table_struct_xml_string = _read_file($v_table_struct_xml_file);
$v_formfield_xml_string = _read_file($v_formfield_xml_file);
//echo htmlspecialchars($v_formfield_xml_string);
//Doc va ghi ra tieu de cua form
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_table_struct_xml_string);
$table_struct_rax->record_delim = 'common_para';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
$table_struct_row = $table_struct_rec->getRow();
$v_form_title = $table_struct_row["form_title"];
$v_first_col_width = $table_struct_row["first_col_width"];
$v_second_col_width = (100-$v_first_col_width)."%";
$v_js_file_name = $table_struct_row["js_file_name"];
$v_js_function  = $table_struct_row["js_function"];
if (!is_null($v_title)&&($v_title!="")){
	$v_form_title = $v_title;
}
///Begin//Form
$v_html_string = '<script src="../js-record/'.$v_js_file_name.'"></script>';
//Begin//Bang chua cac thanh phan cua form
$v_html_string = $v_html_string . "<table width='100%'  border='0' cellspacing='0' cellpadding='0'><tr>";
$v_html_string = $v_html_string . "<td class='large_title'>".$v_form_title."</td>";
$v_html_string = $v_html_string . "</tr></table>";
//Bang chua cac bin hidden
$v_html_string = $v_html_string . "<table width='100%' cellpadding='0' cellspacing='0'><tr><td>";
$v_html_string = $v_html_string . "<form action='index.php' method='post' name='f_dsp_single_record'>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_list_xml_tag' value=''>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_list_xml_value' value=''>";
$v_html_string = $v_html_string . "<input type='hidden' name='fuseaction' value=''>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_received_date' value='".date("d/m/Y")."'>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_record_id' value='".$v_record_id ."'>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_recordtype_filter' value='".$v_recordtype_filter ."'>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_received_date_filter' value='".$v_receive_date_filter ."'>";
$v_html_string = $v_html_string . "<input type='hidden' name='fuseaction_back' value='".$fuseaction_back."'>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_worktype' value='".$v_worktype."'>";
$v_html_string = $v_html_string . "<input type='hidden' name='hdn_page' value='".$v_page."'>";
$v_html_string = $v_html_string . "</td></tr></table>";
//Doc cac dong cua form	
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_table_struct_xml_string);
$table_struct_rax->record_delim = 'row';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
//Bang chua cac dong cua form
$v_html_string = $v_html_string . "<table width='100%' class='form_table1'  border='0' cellspacing='0' cellpadding='0'><tr><td>";
///Begin///Bang chua cac dong co dinh cua ho so
$v_html_string = $v_html_string . "<table width='100%'  border='0' cellspacing='0' cellpadding='0'>";
$v_html_string = $v_html_string . "<col width='21%'><col width='29%'><col width='20%'><col width='30%'>";
$v_html_string = $v_html_string . "<tr><td class='normal_label' align='left'>&nbsp;".CONST_RECORD_TYPE_LABEL."</td>";
$v_html_string = $v_html_string . "<td colspan='3' class='normal_label'>&nbsp;";
$v_html_string = $v_html_string . Get_text_from_array($_SESSION['recordtype'],'PK_RECORDTYPE','PK_RECORDTYPE','C_NAME', $v_recordtype_filter);
$v_html_string = $v_html_string . "</td></tr>";
$v_html_string = $v_html_string . "<tr><td class='normal_label'>&nbsp;".CONST_RECORD_CODE_LABEL."</td><td class='normal_label'>".$v_code_record."</td>";
$v_html_string = $v_html_string . "<td class='normal_label'>&nbsp;".CONST_RESULT_DATE_LABEL."</td><td class='normal_label'>".$v_result_date."</td></tr>";
//$v_html_string = $v_html_string . "<tr><td class='normal_label'>".CONST_RECORD_RECEIVED_DATE_LABEL."<small class='normal_starmark'>*</small></td><td><input type='text' name='txt_received_date' class='normal_textbox' style='width:85%' value='$v_received_date' optional='' message = '".CONST_RECORD_RECEIVED_DATE_MESSAGE."' isdate='true' onChange='get_appoint_date(document.forms(0).txt_received_date,$v_process_date,document.forms(0).txt_appointed_date,$v_current_year);' onKeyDown='change_focus(document.forms(0),this)'>";
//$v_html_string = $v_html_string . "<img src='". $_ISA_IMAGE_URL_PATH."calendar.gif' border='0' onclick='DoCal($v_url_path_calendar,document.forms(0).txt_received_date);get_appoint_date(document.forms(0).txt_received_date,$v_process_date,document.forms(0).txt_appointed_date,$v_current_year);' style='cursor:hand'></td>";
//$v_html_string = $v_html_string . "<td class='normal_label'>".CONST_RECORD_APPOINTED_DATE_LABEL."<small class='normal_starmark'>*</small></td><td><input type='text' name='txt_appointed_date' class='normal_textbox' style='width:85%' value='$v_appointed_date' optional='' message = '".CONST_RECORD_APPOINTED_DATE_MESSAGE."' isdate='true' onKeyDown='change_focus(document.forms(0),this)'>";
//$v_html_string = $v_html_string . "<img src='". $_ISA_IMAGE_URL_PATH."calendar.gif' border='0' onclick='DoCal($v_url_path_calendar,document.forms(0).txt_appointed_date);' style='cursor:hand'></td></tr>";
//$v_html_string = $v_html_string . "<tr><td class='normal_label' align='left'>".CONST_RECORD_CURRENT_STATUS_LABEL."</td>";
//$v_html_string = $v_html_string . "<td colspan='3'><select class='normal_selectbox' name='sel_recordtype' disabled optional='true' style='width:100%'>";
//$v_html_string = $v_html_string . _generate_select_option($arr_record_status,'0','0','1', $v_current_status);
$v_html_string = $v_html_string . "<tr><td class='normal_label'>&nbsp;".CONST_CURRENT_STATUS_LABEL."</td><td colspan='3' class='normal_label'>";
$v_html_string = $v_html_string . $v_current_status_vunh;
$v_html_string = $v_html_string . "</td></tr>";
//$v_html_string = $v_html_string . "</select></td></tr>";
$v_html_string = $v_html_string . "</table>";
///End///Bang chua cac dong co dinh cua ho so
//echo htmlspecialchars($v_xml_str);
while ($table_struct_rec) { 
	$table_struct_row = $table_struct_rec->getRow();
	$v_have_line_before = $table_struct_row["have_line_before"];
	$v_col_number = $table_struct_row["col_number"];
	$v_tag_list = $table_struct_row["tag_list"];
	$v_row_id = $table_struct_row["row_id"];
	$arr_tag = explode(",", $v_tag_list);
	if ($v_have_line_before=="true"){
		$v_html_string = $v_html_string . "<table width='100%'  border='0' cellspacing='0' cellpadding='0'><tr>";
		$v_html_string = $v_html_string . "<td><hr width='100%' color='#66CCFF' size='1'></td>";
		$v_html_string = $v_html_string . "</tr></table>";
	}
	//Bang chua mot dong cua form
	$v_html_string = $v_html_string . "<table width='100%'  border='0' cellspacing='0' cellpadding='0'>";
	$v_html_table = "";
	$v_html_tag = "";			
	for($i=0;$i < sizeof($arr_tag);$i++){
		$formfield_rax = new RAX(); 
		$formfield_rec = new RAX(); 
		$formfield_rax->open($v_formfield_xml_string);
		$formfield_rax->record_delim = $arr_tag[$i];
		$formfield_rax->parse();
		$formfield_rec = $formfield_rax->readRecord(); 
		$formfield_row = $formfield_rec->getRow(); 
		$v_label = $formfield_row["label"];
		$v_type = $formfield_row["type"];
		$v_dataformat = $formfield_row["data_format"];
		$v_width = $formfield_row["width"];
		$v_row = $formfield_row["row"];
		$v_max = $formfield_row["max"];
		$v_min = $formfield_row["min"];
		$v_note = $formfield_row["note"];
		$v_tooltip = $formfield_row["tooltip"];
		$v_message = $formfield_row["message"];
		$v_optional = $formfield_row["optional"];
		$v_maxlength = $formfield_row["maxlength"];
		$v_xml_data = $formfield_row["xml_data"];
		$v_column_name = $formfield_row["column_name"];
		$v_xml_tag_in_db = $formfield_row["xml_tag_in_db"];
		$v_js_function_list = $formfield_row["js_function_list"];
		$v_js_action_list = $formfield_row["js_action_list"];
		$v_relate_recordtype = $formfield_row["relate_recordtype"];
		$v_readonly_in_edit_mode = $formfield_row["readonly_in_edit_mode"];
		$v_disabled_in_edit_mode = $formfield_row["disabled_in_edit_mode"];
		$arr_xml_tag_in_db = explode(".",$v_xml_tag_in_db);
		if (sizeof($arr_xml_tag_in_db)>1){
			$v_xml_str = $arr_single_record[$arr_xml_tag_in_db[0]];
			//echo htmlspecialchars($v_xml_str);
			$v_xml_tag_in_db = $arr_xml_tag_in_db[1];
		}
		if (is_null($v_xml_str)||$v_xml_str==""){
			$v_xml_str = '<?xml version="1.0" encoding="UTF-8"?><root><data_list></data_list></root>';
		}		
		if ($v_xml_str!="" && $v_xml_data=="true"){
			$column_rax = new RAX(); 
			$column_rec = new RAX();
			$column_rax->open($v_xml_str);
			$column_rax->record_delim = 'data_list';
			$column_rax->parse();
			$column_rec = $column_rax->readRecord(); 
			$column_row = $column_rec->getRow();
			$v_value = _restore_XML_bad_char($column_row[$v_xml_tag_in_db]); 
		}else{
			$v_value = $arr_single_record[$v_column_name];
		}
		
		if ($v_type=="selectbox"){
			$v_selectbox_option_sql = $formfield_row["selectbox_option_sql"];
			$v_selectbox_id_column = $formfield_row["selectbox_option_id_column"];
			$v_selectbox_name_column = $formfield_row["selectbox_option_name_column"];
		}
		if ($v_type=="checkboxmultiple"){
			$v_checkbox_multiple_sql = $formfield_row["checkbox_multiple_sql"];
			$v_checkbox_multiple_id_column = $formfield_row["checkbox_multiple_id_column"];
			$v_checkbox_multiple_name_column = $formfield_row["checkbox_multiple_name_column"];
		}
		$v_html_table = $v_html_table . "<col width='$v_first_col_width'>" . "<col width='$v_second_col_width'>";		
		$v_html_tag = $v_html_tag . Generate_HTML_Output();		
	}
	$v_html_string = $v_html_string .  $v_html_table . "<tr id = '$v_row_id' style='display:block'>" . "<td class='normal_label'>" . $v_html_tag."</td>";
	$v_html_string = $v_html_string . "</tr></table>";
	$table_struct_rec = $table_struct_rax->readRecord();
}
$v_html_string = $v_html_string . "</td></tr></table>";
//End//Bang chua cac thanh phan cua form
//print form
echo $v_html_string;
?>
<table width='100%'  border='0' cellspacing='0' cellpadding='0'>
	<tr height="10px"><td>&nbsp;</td></tr>
	<tr align="center">
		<td><?php
		if ((($v_is_granted_update)||onegate_is_receiver_for_recordtype($v_staff_id,$v_recordtype_filter,$_SESSION["recordtype"]))&&($v_current_status<>"DANG_THU_LY")&&($v_current_status!="CAP_PHEP")||(($v_current_status=="DANG_THU_LY")&&($v_detail_status == 20))){?>
			<input type='button' class='normal_button' name="btn_update" value='<?php echo _CONST_SAVE_BUTTON;?>' onClick="check_value_in_form();save_hidden_multiple_list(document.forms(0).chk_item_id,',');save_list_onclick(document.forms(0),document.forms(0).hdn_list_xml_tag,document.forms(0).hdn_list_xml_value);btn_save_onclick('UPDATE_RECORD');" onKeyDown="change_focus(document.forms(0),this)">&nbsp;<?php
		}?>
			<!--input type='button' class='normal_button' name="btn_exit" value='<?php echo _CONST_BACK_BUTTON;?>' onClick="btn_back_onclick('DISPLAY_ALL_RECORD');" onKeyDown="change_focus(document.forms(0),this)"-->&nbsp;
			<input type="button" value="<?php echo _CONST_BACK_BUTTON; ?>" name="btn_add" class="normal_button" onClick="btn_back_onclick('<?php echo $_GO_BACK?>')">
		</td>	
	</tr>
</table>
<!--//End//Form-->
</form>
<script language="JavaScript">
	<?php if ($v_record_id<=0){?>
		get_appoint_date(document.forms(0).txt_received_date,<?php echo $v_process_date;?>,document.forms(0).txt_appointed_date,<?php echo $v_current_year;?>);<?php
	}elseif ($v_worktype=="NHAN_HO_SO_BO_SUNG"){?>
		get_appoint_date(document.forms(0).hdn_received_date,<?php echo $v_process_date;?>,document.forms(0).txt_appointed_date,<?php echo $v_current_year;?>);<?php
	}?>
	set_focus(document.forms(0));
</script>